// https://schoolido.lu/api/cards/?page_size=100&page=1


let nameListDom = document.createElement("div");
nameListDom.style.display = "none";

let cardUrlListDom = document.createElement("div");
cardUrlListDom.style.display = "none";

let bodyDom = document.getElementsByTagName("body")[0];
bodyDom.appendChild(nameListDom);
bodyDom.appendChild(cardUrlListDom);

let nameHTML = "";
let cardUrlHTML = "";

let BASE_URL = "https://lostone.kirara.ca/card/";
let targetUrl = "https://schoolido.lu/api/cards/?page_size=100&page=26";

let nameTeamMap = {
    高坂穂乃果:  { name: "高坂穗乃果", team:  "μ's"},
    南ことり:   { name:  "南小鸟", team:  "μ's"},
    園田海未:   { name:  "园田海未", team:  "μ's"},
    絢瀬絵里:   { name:  "绚濑绘里", team:  "μ's"},
    東條希:    { name:   "东条希", team:  "μ's"},
    矢澤にこ:   { name:  "矢泽妮可", team:  "μ's"},
    星空凛:    { name:   "星空凛", team:  "μ's"},
    西木野真姫:  { name: "西木野真姬", team:  "μ's"},
    小泉花陽:   { name:  "小泉花阳", team:  "μ's"},

    高海千歌:   { name:  "高海千歌", team: "Aqours"},
    桜内梨子:   { name:  "樱内梨子", team: "Aqours"},
    渡辺曜:    { name:   "渡边曜", team: "Aqours"},
    津島善子:   { name:  "津岛善子", team: "Aqours"},
    国木田花丸:  { name: "国木田花丸", team: "Aqours"},
    黒澤ルビィ:  { name: "黑泽露比", team: "Aqours"},
    小原鞠莉:   { name:  "小原鞠莉", team: "Aqours"},
    松浦果南:   { name:  "松浦果南", team: "Aqours"},
    黒澤ダイヤ:  { name: "黑泽黛雅", team: "Aqours"},

    優木せつ菜: { name: "优木雪菜", team: "虹团"},
    NakasuKasumi: { name: "中须霞", team: "虹团"},
    桜坂しずく: { name: "樱坂雫", team: "虹团"},
    TennojiRina: { name: "天王寺璃奈", team: "虹团"},
    AsakaKarin: { name: "朝香果林", team: "虹团"},
    近江彼方: { name: "近江彼方", team: "虹团"},
    エマベルデ: { name: "艾玛·维尔德", team: "虹团"},
    上原歩夢: { name: "上原步梦", team: "虹团"},
    宮下愛: { name: "宫下爱", team: "虹团"},

    鹿角理亞: { name: "鹿角理亚", team: "Saint Snow"},
    鹿角聖良: { name: "鹿角圣良", team: "Saint Snow"},
    綺羅ツバサ: { name: "绮罗翼", team: "A_RISE"},
    優木あんじゅ: { name: "优木杏树", team: "A_RISE"},
    統堂英玲奈: { name: "统堂英玲奈", team: "A_RISE"},
}

while (targetUrl !== null) {
    getInfo(targetUrl);
}
nameListDom.innerHTML = nameHTML;
cardUrlListDom.innerHTML = cardUrlHTML;
console.log("end ! ")


function getInfo(url) {
    let xml = new XMLHttpRequest();
    xml.open("GET", url, false);
    xml.onreadystatechange = function() {
        if (xml.readyState === 4 && xml.status === 200) {
            let data = JSON.parse(xml.responseText);

            let cardInfoList = data["results"];
            for (let i = 0; i < cardInfoList.length; i++) {
                let cardInfo = cardInfoList[i];

                // id
                let cardId = cardInfo["id"];
                if (cardId <= 2662) {
                    continue;
                }
                // 等级 R SR SSR UR
                let rarity = cardInfo["rarity"];
                if (rarity === "N" || rarity === "n") {
                    continue;
                }
                // 偶像团体
                let team = cardInfo["idol"]["main_unit"];
                if (team === null || team === "") {
                    team = "NULL";
                }
                if (team === "A-RISE") {
                    team = "A_RISE"
                }

                // 偶像名
                let idolName = cardInfo["idol"]["japanese_name"];
                if (idolName === null || idolName === "") {
                    idolName = cardInfo["idol"]["name"];
                }
                idolName = idolName.replace(/ +|　+/g, "");
                if (nameTeamMap[idolName] !== undefined) {
                    team = nameTeamMap[idolName]["team"];
                    idolName = nameTeamMap[idolName]["name"];
                }
                // 技能信息
                let skill = cardInfo["japanese_skill"];
                if (skill === null || skill === "") {
                    skill = "NULL";
                }
                skill = skill.replaceAll("-", "_");
                // 篇章
                let collection = cardInfo["japanese_collection"];
                if (collection === null || collection === "") {
                    collection = "NULL";
                }
                collection = collection.replaceAll("-", "_", "sfd");

                // id  团体  偶像名  篇章  级别  觉醒  技能

                let cardIdolizedUrl = BASE_URL + "card_" + cardId + "_ct.png";
                let cardIdolizedTransUrl = BASE_URL + "navi_" + cardId + "_t.png";

                let cardIdolizedName = "card_" + cardId + "_ct~~~SIF卡牌-" + cardId + "-" + team + "-" + idolName + "-" + collection + "-" + rarity + "-觉醒-" + skill;
                let cardIdolizedTransName = "navi_" + cardId + "_t~~~SIF立绘-" + cardId + "-" + team + "-" + idolName + "-" + collection + "-" + rarity + "-觉醒-" + skill;

                cardUrlHTML += cardIdolizedUrl + "<br />" + cardIdolizedTransUrl + "<br />";
                nameHTML += cardIdolizedName + "<br />" + cardIdolizedTransName + "<br />";
                console.log(cardIdolizedName)
                console.log(cardIdolizedTransName)

                if (cardInfo["transparent_image"] !== null) {
                    let cardUrl = BASE_URL + "card_" + cardId + "_c.png";
                    let cardTransUrl = BASE_URL + "navi_" + cardId + ".png";

                    let cardName = "card_" + cardId + "_c~~~SIF卡牌-" + cardId + "-" + team + "-" + idolName + "-" + collection + "-" + rarity + "-普通-" + skill;
                    let cardTransName = "navi_" + cardId + "~~~SIF立绘-" + cardId + "-" + team + "-" + idolName + "-" + collection + "-" + rarity + "-普通-" + skill;

                    cardUrlHTML += cardUrl + "<br />" + cardTransUrl + "<br />";
                    nameHTML += cardName + "<br />" + cardTransName + "<br />";
                    console.log(cardName)
                    console.log(cardTransName)
                }
            }
            targetUrl = data["next"];


        }
    }
    xml.send();
}